package com.boatAnchorAssistant.service.controller.app;

import com.boatAnchorAssistant.pojo.param.device.CreateDeviceParam;
import com.boatAnchorAssistant.pojo.param.device.EditDeviceParam;
import com.boatAnchorAssistant.pojo.param.device.GetDeviceDownListParam;
import com.boatAnchorAssistant.pojo.param.device.GetDeviceListParam;
import com.boatAnchorAssistant.pojo.vo.device.GetDeviceDownListVo;
import com.boatAnchorAssistant.pojo.vo.device.GetDeviceListVo;
import com.boatAnchorAssistant.pojo.vo.device.GetDeviceVo;
import com.boatAnchorAssistant.service.service.in.DeviceService;
import nirvana.core.domains.vo.ApiResult;
import nirvana.core.domains.vo.PageResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * app/设备
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@RestController
@RequestMapping("/device/app")
public class DeviceAppController {

    private final DeviceService service;

    public DeviceAppController(DeviceService service) {
        this.service = service;
    }

    /**
     * 获取设备详情
     *
     * @param id
     * @return
     */
    @GetMapping("/getDevice")
    public ApiResult<GetDeviceVo> getDevice(@RequestParam("id") Long id) {
        GetDeviceVo vo = service.getDevice(id);
        return ApiResult.ok(vo);
    }

    /**
     * 获取设备列表
     *
     * @param param
     * @return
     */
    @PostMapping("/getDeviceList")
    public ApiResult<PageResult<GetDeviceListVo>> getDeviceList(@RequestBody GetDeviceListParam param) {
        param.setIsCollect(true);
        param.setIsDataSegregation(true);
        PageResult<GetDeviceListVo> result = service.getDeviceList(param);
        return ApiResult.ok(result);
    }

    /**
     * 获取设备下拉列表
     *
     * @return
     */
    @PostMapping("/getDeviceDownList")
    public ApiResult<List<GetDeviceDownListVo>> getDeviceDownList(@RequestBody(required = false) @Valid GetDeviceDownListParam param) {
        param.setIsDataSegregation(true);
        List<GetDeviceDownListVo> list = service.getDeviceDownList(param);
        return ApiResult.ok(list);
    }

}

